import {
  getUserList,
  getRoleList,
  getAllRoleList,
} from '@/network/api/userListApi';
import { getMemberList, getMemberListDetail, addWorkspaceUser, deleteWorkspaceUser } from '@/network/api/commonApi';
let initState = () => ({
  tabList: [],//首页table
  total: 0,
  pageSize: 10,
  pageNum: 1,
  operationType: 'dataSee', //判断操作类型

  // /***********详情页需要用到的所有用户角色合集****************** */
  // allRoleList: [], //所有角色集合
  
  // 弹窗中的数据
  addVisible: false,//控制模态框,添加成员调用


  /****************弹窗添加用户***************** */
  allMember: [], //所有用户

  /************* 详情页需要用到空间id ****************/
  workSpaceId:"",//空间id
  detailList: {},//查看详情数据
  memberListTabDel:[],//空间详情页 成员 table数据
});

export default {
  namespace: 'memberList',
  state: { ...initState() },
  effects: {
    //查询所有角色
    *getAllRoleList({ payload }, { call, put }) {
      return yield call(getAllRoleList);
    },
    // 获取角色列表
    *getRoleList({ payload }, { call, put }) {
      var obj = { params: payload };
      return yield call(getRoleList, obj);
    },
    *getUserList({ payload }, { call, put }) {
      var obj = { params: payload };
      return yield call(getUserList, obj);
    },
    // 获取空间列表
    *getMemberList({ payload }, { call, put }) {
      return yield call(getMemberList);
    },
    // 空间成员列表详情
    *getMemberListDetail({ payload }, { call, put }) {
      return yield call(getMemberListDetail, { params: payload });
    },
    // 空间成员列表 添加
    *addWorkspaceUser({ payload }, { call, put }) {
      return yield call(addWorkspaceUser, { body: payload });
    },
    // 空间成员列表 删除
    *deleteWorkspaceUser({ payload }, { call, put }) {
      return yield call(deleteWorkspaceUser, { body: payload });
    },
    // 空间删除
    *workSpaceDelete({ payload }, { call, put }) {
      return yield call(workSpaceDelete, { params: payload });
    }
  },
  reducers: {
    setState(state, action) {
      return { ...state, ...action.payload };
    },
    init(state, action) {
      return { ...initState(), ...action.payload };
    },
  },
};
